package day03;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Arrays;

public class DemoEncoding {
	public static void main(String[] args) throws UnsupportedEncodingException {
		//把字符串变成字节
//		String s="中";
//		byte[] bytes=s.getBytes("utf-8");
//		for(byte b:bytes) {
//			System.out.println(b);
//		}
//		
//		byte[] bytes1=s.getBytes("iso-8859-1");
//		for(byte b1:bytes1) {
//			System.out.println(b1);
//		}
		
		
		//把字节变成字符串   E5BCA0=张
		byte[] bytes= {(byte) 0xE5,(byte) 0xBC,(byte) 0xA0};
		String s=new String(bytes,"iso-8859-1");
		
		//把乱码字符串变回(原始)字节
		byte[] bytes1=s.getBytes("iso-8859-1");
		for(byte b:bytes1) {
			System.out.println(Integer.toHexString(b));
		}
		
		//根据原始字节,通过utf-8重新编码成字符串
		
		String s1=new String(bytes1,"utf-8");
		System.out.println(s1);
		
		
		String s2="张三";
		System.out.println(URLEncoder.encode(s2,"utf-8"));
		
	}
}
